package com.satchi.struts.action.balance;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.satchi.commons.PageHelp;
import com.satchi.entiy.Page_e;
import com.satchi.hib.pojo.FinBalance;
import com.satchi.service.GetBalanceService;
import com.satchi.struts.ActionHelper;

public class BalanceallinfoAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String searchKey = request.getParameter("s");

		GetBalanceService gbs = new GetBalanceService();
		int totalRows;
		Page_e page;
		List<FinBalance> returnList;
		
		if(ActionHelper.IsEmpty(searchKey)) {
			totalRows = gbs.getCount();
			page = PageHelp.getPager(request, totalRows);
			returnList = gbs.getPageList(page.getStartRow(), page.getPageSize());
		} else {
			totalRows = gbs.getSearchCount(searchKey);
			page = PageHelp.getPager(request, totalRows);
			returnList = gbs.getSearchPage(searchKey, page.getStartRow(), page.getPageSize());
			request.setAttribute("s", searchKey);
			request.setAttribute("isSearching", "searching");
		}
		
		request.setAttribute("page",page);
		request.setAttribute("list",returnList);
		request.setAttribute("totalRows", totalRows);
		return mapping.findForward("success");
	}
	
}
